#include<bits/stdc++.h>
using namespace std;
struct node{
	int num;
	string op,ad;
	bool alive;
}a[10001];
int n;
map<string,int> ms;
int x=0;
void ha(){
	for(int i=1;i<=n;i++){
		x=0;
		int k=1;
		for(int j=0;j<a[i].ad.size();j++){
			if(k==1){
				if(j==0&&a[i].ad[j]<='0'||a[i].ad[j]>'9')
					a[i].alive=1;
				else if(j==0)
					x=x*10+a[i].ad[j]-'0';
				if(j!=0){
					if(a[i].ad[j]=='.'){
						k++;
						if(x<0||x>255)
							a[i].alive=1;
							x=0;
							continue;
					}
					if(a[i].ad[j]<'0'||a[i].ad[j]>'9')
						a[i].alive=1;
					else
						x=x*10+a[i].ad[j]-'0';
				}
			}
			if(k==2){
				if(a[i].ad[j-1]=='.'&&a[i].ad[j]<='0'||a[i].ad[j]>'9')
					a[i].alive=1;
				else if(a[i].ad[j-1]=='.')
					x=x*10+a[i].ad[j]-'0';
				if(a[i].ad[j-1]!='.'){
					if(a[i].ad[j]=='.'){
						k++;
						if(x<0||x>255)
							a[i].alive=1;
						x=0;
							continue;
					}
					if(a[i].ad[j]<'0'||a[i].ad[j]>'9')
						a[i].alive=1;
					else
						x=x*10+a[i].ad[j]-'0';
				}
			}
			if(k==3){
				if(a[i].ad[j-1]=='.'&&a[i].ad[j]<='0'||a[i].ad[j]>'9')
					a[i].alive=1;
				else if(a[i].ad[j-1]=='.')
					x=x*10+a[i].ad[j]-'0';
				if(a[i].ad[j-1]!='.'){
					if(a[i].ad[j]=='.'){
						k++;
						if(x<0||x>255)
							a[i].alive=1;
						x=0;
							continue;
					}
					if(a[i].ad[j]<'0'||a[i].ad[j]>'9')
						a[i].alive=1;
					else
						x=x*10+a[i].ad[j]-'0';
				}
			}
			if(k==4){
			if(a[i].ad[j-1]=='.')
				if(a[i].ad[j]<='0'||a[i].ad[j]>'9')
					a[i].alive=1;
				else if(a[i].ad[j-1]=='.')
					x=x*10+a[i].ad[j]-'0';
				if(a[i].ad[j-1]!='.'){
					if(a[i].ad[j]==':'){
						k++;
						if(x<0||x>255)
							a[i].alive=1;
						x=0;
							continue;
					}
					if(a[i].ad[j]<'0'||a[i].ad[j]>'9')
						a[i].alive=1;
					else
						x=x*10+a[i].ad[j]-'0';
				}
			}
			if(k==5){
				if(a[i].ad[j-1]==':'&&a[i].ad[j]<='0'||a[i].ad[j]>'9')
					a[i].alive=1;
				else if(a[i].ad[j-1]==':')
					x=x*10+a[i].ad[j]-'0';
				if(a[i].ad[j-1]==':'&&j+1==(a[i].ad.size())){
						k++;
						if(x<0||x>65535)
							a[i].alive=1;
						x=0;
					}
				if(a[i].ad[j-1]!=':'){
					if(a[i].ad[j]<'0'||a[i].ad[j]>'9')
						a[i].alive=1;
					else
						x=x*10+a[i].ad[j]-'0';
					if(j+1==(a[i].ad.size())){
						k++;
						if(x<0||x>65535)
							a[i].alive=1;
						x=0;
							continue;
					}
				}
			}
		}
		if(k!=6)
		a[i].alive=1;
	}
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].op>>a[i].ad;
		a[i].num=i;
	}
	for(int i=1;i<=n;i++){
		if(a[i].op[0]=='S'){
			if(!a[i].alive&&ms[a[i].ad]==0){
				cout<<"OK\n";
				ms[a[i].ad]=i;
			}
			else if(a[i].alive){
				cout<<"ERR\n";
			}
			else {
				cout<<"FAIL\n";
			}
		}
		else{
			if(!a[i].alive&&ms[a[i].ad]){
				cout<<ms[a[i].ad]<<endl;
			}
			else if(a[i].alive){
				cout<<"ERR\n";
			}	
			else 
			cout<<"FAIL\n";
		}
	}
	return 0;
}
